package com.dongrj.framework.web.redisson;

import org.redisson.Redisson;
import org.redisson.client.codec.StringCodec;
import org.redisson.config.Config;

public class CustomRedisson extends Redisson {

    private static volatile CustomRedisson instance;

    protected CustomRedisson(Config config) {
        super(config);
    }

    private static Config getEnvConfig() {
        String address = "redis://127.0.0.1:6379";
        Config config = new Config();
        config.setCodec(StringCodec.INSTANCE);
        config.useSingleServer().setAddress(address);
        return config;
    }

    public static CustomRedisson getInstance() {
        if (instance == null) {
            synchronized (CustomRedisson.class) {
                if (instance == null) {
                    Config config = getEnvConfig();
                    instance = new CustomRedisson(config);
                }
            }
        }
        return instance;
    }
}
